
//
//  StatisticViewController.m
//  BOSS-SOOC
//
//  Created by apple on 16/9/5.
//  Copyright © 2016年 Gcx. All rights reserved.
//
#define orige [self getColor:@"ff8a00"]
#define REDCOLOR [self getColor:@"e86666"]


#import "StatisticViewController.h"
#import "TotalModel.h"
#import "AbsentTableView.h"
#import "AbsentClassViewController.h"

@interface StatisticViewController ()<AbsentTableViewDelegate>{

    TotalModel *_myModel;
}

@end

@implementation StatisticViewController

- (void)viewDidLoad{

    [super viewDidLoad];
    
    [self setNavBarTitle:@"缺席统计"];
    

    [self addMainView];
}

- (void)addMainView{

    [self creatTopView];
    
    AbsentTableView *table = [[AbsentTableView alloc]initWithFrame:CGRectMake(0, 73+ScaleSize(207), SIZEWIDTH, SIZEHEIGHT - 73) style:UITableViewStyleGrouped];
    table.sc_delegate = self;
    
    table.countBlock = ^(id count){
    
        UILabel *label = (UILabel *)[self.view viewWithTag:101];
        
        label.text = [NSString stringWithFormat:@"%@",count];
    };
    
    table.kcid = _myModel.kcid;
    [self.view addSubview:table];
}

- (instancetype)getTotalModel:(TotalModel *)model{

    _myModel = model;
    
    return self;
}

- (void)tableView:(AbsentTableView *)tableView didSelectModel:(AbsentModel *)model{

    AbsentClassViewController *vc = [[AbsentClassViewController alloc]getModel:model andKcid:_myModel.kcid andKcmc:_myModel.kcmc];
    
    vc.hidesBottomBarWhenPushed = YES;
    
    [self navigationCanDragBack:YES];
    
    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma mark -- creatTopView
- (void)creatTopView{

    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, SIZEWIDTH, ScaleSize(207))];
    
    topView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:topView];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, ScaleSize(207)-0.5, SIZEWIDTH, 0.5)];
    view.backgroundColor = colordbdbdb;
    [topView addSubview:view];
    
    self.view.backgroundColor = BGC;

    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScaleSize(42), ScaleSize(42), 150, 20)];
    titleLabel.font = NormalFont(42);
    titleLabel.text = _myModel.kcmc;
    titleLabel.textColor = Color333333;
    
    UILabel *classLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScaleSize(42), CGRectGetMaxY(titleLabel.frame)+ScaleSize(33), 150, 20)];
    classLabel.font = NormalFont(42);
    classLabel.text = _myModel.skxq;
    classLabel.textColor = Color999999;
    [topView addSubview:titleLabel];
    [topView addSubview:classLabel];
    
    
    NSArray *array = @[@"缺席人数",@"点名次数"];
    
    for (int i = 1; i <= 2; i++) {
        
        UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(SIZEWIDTH - i*70, ScaleSize(42), 65, 20)];
        lable.textColor = Color333333;
        lable.font = NormalFont(36);
        lable.textAlignment = NSTextAlignmentCenter;
        lable.text = array[i-1];
        [topView addSubview:lable];
    }
    
    for (int i = 1; i <= 2; i++) {
        
        UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(SIZEWIDTH - i*70, ScaleSize(75)+15, 65, 20)];
        lable.textColor = [UIColor orangeColor];
        lable.font = NormalFont(42);
        lable.textAlignment = NSTextAlignmentCenter;
        //        lable.text = array[i];
        lable.tag = 102-i;
        if (lable.tag == 100) {
            
            lable.textColor = orige;
        } else {
            
            lable.textColor = REDCOLOR;
        }
        
        [topView addSubview:lable];
    }
    
    for (int i = 1; i <= 2; i++) {
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(SIZEWIDTH - i*70, ScaleSize(30), 0.5, ScaleSize(147))];
        view.backgroundColor = colordbdbdb;
        [topView addSubview:view];
    }
    
    UILabel *dianming = (UILabel *)[self.view viewWithTag:100];
    dianming.text = _myModel.qdcs;
    
//    UILabel *quexi = (UILabel *)[self.view viewWithTag:101];

}

//16进制颜色转换
-(UIColor *)getColor:(NSString *)hexColor {
    unsigned int red,green,blue;
    NSRange range;
    range.length = 2;
    
    range.location = 0;
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];
    
    range.location = 2;
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];
    
    range.location = 4;
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];
    
    return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green / 255.0f) blue:(float)(blue / 255.0f) alpha:1.0f];
}

@end
